package org.example.studyonline.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.example.studyonline.mapper.CommentMapper;
import org.example.studyonline.pojo.Comment;
import org.example.studyonline.pojo.DTO.CommentDTO;
import org.example.studyonline.service.CommentService;
import org.example.studyonline.utils.AuthUtils;
import org.example.studyonline.utils.BeanCopyUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {

    @Resource
    private CommentMapper commentMapper;
    @Override
    public Map comment(CommentDTO commentDTO) {
        Comment comment = BeanCopyUtils.copyBean(commentDTO, Comment.class);
        comment.setUserID(AuthUtils.getUserID());
        comment.setCreatedAt(LocalDateTime.now());
        commentMapper.insert(comment);
        HashMap<String, Integer> map = new HashMap<>();
        map.put("commentID",comment.getCommentID());
        return map;
    }
}
